var gulp = require('gulp');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify-es').default;
var htmlmin = require('gulp-htmlmin'); //html压缩
var cssmin = require('gulp-cssmin'); //压缩CSS


// js压缩命令
gulp.task('js', function () {
    var option = {
        removeComments: true,
        minifyJS: true
    }
    gulp.src(['js/module-toggleFloorBtn.js', 'js/wxshare.js','js/index.js'])
        .pipe(uglify())
        .pipe(concat('ZSFSDBYYmap.min.js'))
        .on('error', function (e) {
            console.log(e);
        })
        .pipe(gulp.dest('js'));
    return new Promise(function (resolve, reject) {
        console.log("HTTP Server Started");
        resolve();
    });
})

gulp.task('css', function () {
    gulp.src(['css/index.css', 'css/reset.css'])
        .pipe(concat('ZSFSDBYYmap.css'))
        .pipe(cssmin())
        .pipe(gulp.dest('mincss'))
    //  {compatibility: 'ie8'}  兼容ie8
    return new Promise(function (resolve, reject) {
        console.log("HTTP Server Started");
        resolve();
    });
});
gulp.task('html', function () {
    var options = {
        removeComments: true, //清除HTML注释
        collapseWhitespace: true, //压缩HTML
        minfyJS: true, //压缩JS
        minfyCss: true, //压缩CSS
    };
    gulp.src('index.html')
        .pipe(htmlmin(options))
        .pipe(rename('index.html'))
        .pipe(gulp.dest('htmlmin'))
    return new Promise(function (resolve, reject) {
        console.log("HTTP Server Started");
        resolve();
    });
});

//注册默认任务
// gulp.task('default', ['js', 'css','html']);